package com.huanwei.mini.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.huanwei.mini.R;
import com.huanwei.mini.adapter.Recycle_Baseadapter;
import com.huanwei.mini.http.API;
import com.huanwei.mini.http.ML;
import com.huanwei.mini.utils.JSONUtils;
import com.huanwei.mini.utils.Okhttp;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 *
 */
public class GZ_Fragment extends Fragment {


    View view;

    Unbinder unbinder;
    @BindView(R.id.recycleview)
    RecyclerView order_RecyclerView;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (view == null) {
            view = View.inflate(getActivity(), R.layout.fragment_gz, null);
            ButterKnife.bind(this, view);

            cc();

        }
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }

        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    Recycle_Baseadapter adapter;

    public void cc() {
        order_RecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        order_RecyclerView.setItemAnimator(new DefaultItemAnimator());

        API.gz(getActivity(), new Okhttp.Objectcallback() {
            @Override
            public void onsuccess(String st) {
                Log.e("xx", "xx"+st);
                ML ml = JSONUtils.parseJSON(st, ML.class);
                if (ml.getError().equals("0")) {
                   ML.SdataBean sdata= ml.getSdata();
                    List<ML.SdataBean.FirstBean> first = sdata.getFirst();
                    adapter = new Recycle_Baseadapter(first);
                    adapter.adddata(getActivity());

                    order_RecyclerView.setAdapter(adapter);
                } else {
                    Toast.makeText(getActivity(), "服务器错误！", Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onFalia(int code, String errst) {
                Log.e("111", "xx"+errst);
                Toast.makeText(getActivity(), "网络错误，"+errst, Toast.LENGTH_SHORT).show();


            }
        });
    }


}

